import sqlite3


class SqliteClass:

    def __init__(self,dbname):
        self.conn = sqlite3.connect(dbname)
        self.cursor = self.conn.cursor()


    def create_table(self,table_name,s):
        try:
            self.cursor.execute(f'create table {table_name} {s}')
        except:
            pass

    def insert_data(self,table_name,name,url,image_url,video_type):
        try:
            if table_name == "video2":
                self.cursor.execute(f'insert into {table_name} (name,url,image_url,video_type) values (?,?,?,?)',
                                    (name, url, image_url, video_type))
            # elif table_name == "video2":
            #     self.cursor.execute(f'insert into {table_name} (name,url,status) values (?,?,?)',
            #                         (name, url, image_url, video_type))
            # print(self.cursor.rowcount)

            self.conn.commit()
        except:
            pass
    def select_all(self):
        self.cursor.execute('select * from video')
        values = self.cursor.fetchall()
        return values
    def __del__(self):
        self.conn.close()
